﻿using System;
using System.Collections.Generic;
using System.Web;
using HySoft.Cash.Business;
using System.Data;
using System.Web.UI;
using System.Web.SessionState;
using System.Web.Profile;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace PayRoller
{
    public class Login : Page, IRequiresSessionState
    {
        // Fields
        protected Button Button1;
        protected HtmlForm form1;
        protected Label lblTip;
        protected TextBox txtPassWord;
        protected TextBox txtUserName;

        // Methods
        protected void Button1_Click(object sender, EventArgs e)
        {
            TorginfoBN obn = new TorginfoBN(this.Page);
            obn.QueryUserName(this.txtUserName.Text);
            obn.QueryPassWord(this.txtPassWord.Text);
            obn.QueryIsValid(1);
            DataTable list = obn.GetList();
            obn.Dispose();
            obn = null;
            if (list.Rows.Count > 0)
            {
                base.Response.Cookies["Company.ID"].Value = list.Rows[0]["Sid"].ToString();
                base.Response.Cookies["Company.ID"].Expires = DateTime.Now.AddHours(12.0);
                base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>window.location='Member/Index.aspx';</script>");
            }
            else
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Sorry,the account does not exist(or not open)!');</script>");
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Button1.Attributes.Add("onclick", "return Check();");
        }

        // Properties
        protected HttpApplication ApplicationInstance
        {
            get
            {
                return this.Context.ApplicationInstance;
            }
        }

        protected DefaultProfile Profile
        {
            get
            {
                return (DefaultProfile)this.Context.Profile;
            }
        }
    }

}
